package ge.telasi.tasks.ui.user;

import ge.telasi.tasks.model.Group;
import ge.telasi.tasks.ui.comp.CommonDialog;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

/**
 * @author dimitri
 */
public class GroupPickDialog extends CommonDialog {
    GroupList list;
    boolean approved;

    public GroupPickDialog(Component parent) {
        super(parent, true);
        initComponents();
        setSize(500, 300);
        setTitle("ჯგუფის არჩევა");
    }

    private void initComponents() {
        list = new GroupList();
        JPanel bottom = new JPanel(new BorderLayout());
        bottom.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        JButton btnOk = new JButton("არჩევა");
        JButton btnCancel = new JButton("გაუქმება");
        bottom.add(btnOk, BorderLayout.EAST);
        bottom.add(btnCancel, BorderLayout.WEST);
        btnOk.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (getSelectedGroup() != null) {
                    approved = true;
                    dispose();
                }
            }
        });
        btnCancel.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                approved = false;
                dispose();
            }
        });
        // place in dialog
        getContentPane().setLayout(new BorderLayout());
        getContentPane().add(new JScrollPane(list), BorderLayout.CENTER);
        getContentPane().add(bottom, BorderLayout.SOUTH);
        getRootPane().setDefaultButton(btnOk);
    }

    public Group getSelectedGroup() {
        return list.getSelectedGroup();
    }

    public List<Group> getSelectedGroups() {
        return list.getSelectedGroups();
    }

    public void refresh() {
        list.refresh();
    }

    public boolean isApproved() {
        return approved;
    }

}
